import requests

from conf.comm import host


class TestInterface:
    def __init__(self, method, url, data=''):
        if method == 'post':
            self.res = requests.post(url, data)
        else:
            self.res = requests.get(url)

    # 把返回的结果转成json
    def get_content(self):
        return self.res.json()


# 测试登录
# 调用发送验证码通过手机号获取验证码
testinterface = TestInterface('post', 'http://localhost:5000/users/sendsms',
                              {'mobile': 13289792767})

# 获取结果
res = testinterface.get_content()

# 判断
if res['code'] == 200:
    # 从结果集中获取验证码
    code = res['smscode']
    # 调用登录接口传入手机号和验证码
    interface = TestInterface('post', 'http://localhost:5000/users/login',
                              {'mobile': 13289792767, 'code': code})
    res = interface.get_content()
    print(res)